import React from 'react';
import Grid from '../../components/table/grid';
import tranStartType from '../../utils/tranStartType';
import PublicForm from '../order/publicForm';
import {sessionManager} from '../../utils/sessionStorage';
import moment from 'moment';
import SassNotification from '../../components/notification/notification'
import { injectIntl } from 'react-intl';

class publicCharge extends React.Component {
    constructor(props) {
        super(props);
        this.state={
            params:{
                qryType:2,
                chargeEndTimeStart:moment().subtract('days',31).format('YYYY.MM.DD HH:mm:ss'),
                chargeEndTimeEnd:moment().format('YYYY.MM.DD HH:mm:ss'),
                validFlag:1
            },
            refresh:0,
            gridStyle:{
                scroll:true
            }
        };
        const common = this.props.intl.messages.common;
        this.columns = [
            {
                title: common.orderNO,
                dataIndex: 'id',
                key: 'id',
                width: 320,
                fixed: 'left'
            },
            {
                title: common.launchTime,
                dataIndex: 'startTime',
                key: 'startTime',
                width: 180,
            },
            {
                title: common.endTime,
                dataIndex: 'endTime',
                key: 'endTime',
                width: 180,
            },
            {
                title: common.duration,
                dataIndex: 'chargeTime',
                key: 'chargeTime',
                width: 180,
            },
            {
                title: common.electricQuantity,
                dataIndex: 'electric',
                key: 'electric',
                width: 150,
            },
            {
                title: common.energyCharge,
                dataIndex: 'feeElectric',
                key: 'feeElectric',
                width: 150,
            },
            {
                title: common.serviceCharge,
                dataIndex: 'feeService',
                key: 'feeService',
                width: 150,
            },
            {
                title: common.chargingState,
                dataIndex: 'status',
                key: 'status',
                width: 150,
            },
            {
                title: common.licenseNumber,
                dataIndex: 'plateNo',
                key: 'plateNo',
                width: 150,
            },
            {
                title: common.vinOfCar,
                dataIndex: 'vin',
                key: 'vin',
                width: 180,
            },
            {
                title: common.EquipmentNo,
                dataIndex: 'stubId',
                key: 'stubId',
                width: 150,
            },
            {
                title: common.powerStationName,
                dataIndex: 'stubGroupName',
                key: 'stubGroupName',
                width: 150,
                className:'SC-col-dots'
            },
            {
                title: common.startType,
                dataIndex: 'startType',
                key: 'startType',
                width: 150,
            },
            {
                title: common.endInfo,
                dataIndex: 'endInfo',
                key: 'endInfo',
                width: 400,
                className:'SC-col-dots'
            },
            {
                title: common.operation,
                key: 'operation',
                fixed: 'right',
                width: 100,
                render: (text, record) => (
                    <span>
                        <a  onClick={()=>this.showDiffMoudle(text,record,'chargeProcess')}>{common.chargingProcess}</a>
                    </span>
                ),
            }];
    }
    formSubmit=(data)=>{
        this.setState({
            params: {...data},
            refresh: this.state.refresh + 1
        });
    }
    getTableData=(data)=>{
        this.setState({
            TableData:data
        })
    }
    transformData=(data)=>{
        const common = this.props.intl.messages.common;
        data.forEach((item,index)=>{
            if(item.status===1){
                item.status=common.charging;
            }else{
                item.status=common.chargingCompleted;
            }
            item.startType=tranStartType(item.startType)
            return item
        });
        return data;
    }
    showDiffMoudle(text, record, moudle){
        sessionManager.set('orderInfo',text);
        console.log('orderInfo：',text);
        switch(moudle){
            case 'chargeProcess':
                this.props.history.push('/order/chargeProcess');
                break;
            default:
                this.props.history.push('/order/chargeProcess');
        }
    }
    render(){
        return(
            <div>
                <SassNotification></SassNotification>
                <PublicForm  params={this.state.params} formSubmit={this.formSubmit}></PublicForm>
                <Grid gridStyle={this.state.gridStyle} transformData={this.transformData} refresh={this.state.refresh} params={this.state.params} columns={this.columns} url="api/order/list/qry" />
            </div>
        )
    }
}

export default injectIntl(publicCharge)

